// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import {appRouter} from './router/router';
import store from './store'
// ArcGIS需要
import { loadScript } from 'esri-loader'

// 引入bootstrap4样式源码
import './bootstrap-scss/bootstrap.scss'
// 自定义通用样式
require('./style.scss')
// 自己制作的字体图标库
require('./fonts/style.css')
// wowjs
// require('wowjs/css/libs/animate.css')
// 引入element
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css'
// 自定义验证器
import './validate.js'
// 常用工具插件
import Util from './plugins/util'
// 处理请求参数得插件
import paramsConvert from './plugins/paramsConvert'
// 错误处理
import errorPage from './plugins/errorPage'
// 图片预览
import Viewer from 'v-viewer'
import 'viewerjs/dist/viewer.css'
// 图片懒加载
import VueLazyload from 'vue-lazyload'
// 粒子效果图
import VueParticles from 'vue-particles'
import axios from 'axios'

import 'simplebar'; // or "import SimpleBar from 'simplebar';" if you want to use it manually.
import 'simplebar/dist/simplebar.css';
// wowjs
import { WOW } from 'wowjs'

// axios.defaults.baseURL = 'http://127.0.0.1:3333/'

new WOW(
  {
  //   boxClass:     'wow',      // animated element css class (default is wow)
  //   animateClass: 'animated', // animation css class (default is animated)
  //   offset:       200,          // distance to the element when triggering the animation (default is 0)
  //   mobile:       true,       // trigger animations on mobile devices (default is true)
    live:         false,       // act on asynchronously loaded content (default is true)
  //   callback:     function(box) {
  //     // the callback is fired every time an animation is started
  //     // the argument that is passed in is the DOM node being animated
  //   },
  //   scrollContainer: null // optional scroll container selector, otherwise use window
  }
).init()

// preload the ArcGIS API
const options = {
  // url: 'https://js.arcgis.com/4.8/',
  url: '/static/dojo.min.js'
};
loadScript(options)

Vue.config.productionTip = false

Vue.use(ElementUI)
Vue.use(Util)
Vue.use(paramsConvert)
Vue.use(errorPage)
Vue.use(Viewer)
Vue.use(VueLazyload, {
  preLoad: 1.3,
  loading: 'static/mohubeijing.jpg',
  attempt: 1,
  listenEvents: [ 'scroll' ]
})
Vue.use(VueParticles)

router.beforeEach(function (to, from, next) {
    const nextRoute = []
    // 跳转至上述页面
    if (!store.state.user.user) {
      let user = localStorage.userinfo ? JSON.parse(localStorage.userinfo) : null
      //未登录
      if (!user || new Date().getTime() - user.expires > 24 * 60 * 60 * 1000) {
        if (nextRoute.indexOf(to.name) >= 0) { // 需要用户，增跳转登录也
          next({
            replace: true,
            name: 'home'
          })
          return
        }
      } else {
        store.dispatch('setUser', user)
      }
    }
    next()

})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>',
  mounted () {
      this.currentPageName = this.$route.name;
      // 显示打开的页面的列表
      this.$store.commit('setOpenedList');
      this.$store.commit('initCachepage');
      // 权限菜单过滤相关
      this.$store.commit('updateMenulist');
  },
  created () {
      let tagsList = [];
      appRouter.map((item) => {
          if (item.children.length <= 1) {
              tagsList.push(item.children[0]);
          } else {
              tagsList.push(...item.children);
          }
      });
      this.$store.commit('setTagsList', tagsList);
  }

})
